package org.example.rabbitmq.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.example.rabbitmq.util.ConnectionUtil;

/**
 * @author Lenovo
 * @version 1.0
 * @description TODO
 * @date 25/7/2023 下午4:34
 */
// 工作模式的生产者
public class Producer {
    public static final String QUEUE_NAMQ = "worker_queue";
    public static void main(String[] args) throws Exception {

        // 获取连接
        Connection connection = ConnectionUtil.getConnection();
        // 创建信道
        Channel channel = connection.createChannel();
        // 声明队列
        channel.queueDeclare(QUEUE_NAMQ,true,false,false,null);
        // 一次性发送10条消息
        for (int i = 0;i < 10; i++){
            // 设置消息
            String message = "消息" + i;
            channel.basicPublish("",QUEUE_NAMQ,null,message.getBytes());
        }
        // 关闭资源
        ConnectionUtil.closeResource(channel,connection);
    }
}
